﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.Common;

namespace Com.Becom.CommonLibrary.Db.AdoNet
{

    /// <summary>
    /// 数据库交互抽象类。该类与业务代码紧耦合，与数据库实现解耦。
    /// </summary>
    public abstract class AbstractDb
    {

        /// <summary>
        /// 获取数据库连接字符串。
        /// </summary>
        /// <returns>数据库连接字符串</returns>
        public abstract string GetDbConnectionString();

        /// <summary>
        /// 获取数据库连接。
        /// </summary>
        /// <returns>数据库连接</returns>
        public abstract IDbConnection GetDbConnection();
        public abstract IDbConnection GetDbConnection(string connectionStr);

        /// <summary>
        /// 获取数据库适配器。
        /// </summary>
        /// <returns>数据库适配器</returns>
        public abstract IDbDataAdapter GetDbDataAdapter();

        /// <summary>
        /// 获取数据库命令行。
        /// </summary>
        /// <returns>数据库命令行</returns>
        public abstract IDbCommand GetDbCommand();
        public abstract IDbCommand GetDbCommand(string connStr);

        /// <summary>
        /// 向数据库命令行里追加参数。
        /// </summary>
        /// <param name="SQLCommand">数据库命令行</param>
        /// <param name="dbtype">字段类型</param>
        /// <param name="ParamName">参数名称</param>
        /// <param name="ParamValue">参数值</param>
        /// <returns>添加参数后的数据库命令行</returns>
        public abstract IDbCommand AddParam(IDbCommand SQLCommand, DbType dbtype, string ParamName, object ParamValue);

        /// <summary>
        /// 获取数据集。
        /// </summary>
        /// <param name="SQLCommand">数据查询SQL语句命令行。</param>
        /// <returns>查询结果数据集</returns>
        public abstract DataSet GetDataSet(IDbCommand SQLCommand);

        /// <summary>
        /// 获取数据集。
        /// </summary>
        /// <param name="SQL">数据查询SQL语句。</param>
        /// <returns>查询结果数据集</returns>
        public abstract DataSet GetDataSet(string SQL);

        /// <summary>
        /// 执行数据库命令行。
        /// </summary>
        /// <param name="SQLCommand">数据库命令行</param>
        /// <returns>成功执行影响的记录数</returns>
        public abstract int RunSQL(IDbCommand SQLCommand);

        /// <summary>
        /// 执行SQL更新语句。
        /// </summary>
        /// <param name="SQL">SQL更新语句</param>
        /// <returns>成功执行影响的记录数</returns>
        public abstract int RunSQL(string SQL);

        /// <summary>
        /// 把数据集更新到数据库里。免SQL语句。
        /// </summary>
        /// <param name="dataSet">待入库的数据集</param>
        /// <param name="tablename">目标表名称</param>
        public abstract int UpdateDataSetToDb(DataSet dataSet, string tablename);

        /// <summary>
        /// 获取数据参数类型
        /// </summary>
        /// <param name="cmdParamName">参数名数组</param>
        /// <param name="cmdParamValue">参数值数组</param>
        /// <returns></returns>
        public abstract DbParameter[] GetDbParameter(object[] cmdParamName, object[] cmdParamValue);

        /// <summary>
        /// 获取数据参数类型
        /// </summary>
        /// <param name="cmdParamName">参数名</param>
        /// <param name="cmdParamValue">参数值</param>
        /// <returns></returns>
        public abstract DbParameter[] GetDbParameter(object cmdParamName, object cmdParamValue);
        public abstract DbParameter GetDbParameter(object cmdParamName, object cmdParamValue, ParameterDirection paramDirection);

    }

}
